﻿using UnityEngine;
using System.Collections;

public class keyScript : carryableObject {
	
	Vector3 initPos;
	public interactButton IBut;
	// Use this for initialization
	void Start () {
		initPos = transform.position;
		try
		{
			IBut = GameObject.FindGameObjectWithTag("InteractButton").GetComponent<interactButton>();
		}
		catch
		{
			;
		}
	}
	
	// Update is called once per frame
	void Update () {

	}
	
	public void resetPos()
	{
		transform.position = initPos;
	}
	
	void LateUpdate()
	{
		if(isPlayerIn)
		{
			//if(!player.isGrounded)
			//	return;
				
			//Debug.Log("AW");
			
			if(Input.GetKeyDown(KeyCode.F))
			{
				if(player.latestObject != this && !player.havePickUpThisTurn)
				{
					if(!player.isCarrying && myParent == null)
					{
						//Debug.Log("GET");
						player.havePickUpThisTurn = true;
						player.keyHold(this);
					}
				}
			}
		}
		
		if(myParent != null)
		{
			//Vector3 tmpRot = transform.eulerAngles;
			
			//tmpRot.z = 180 * myParent.direction;
			//transform.eulerAngles = tmpRot;
			
			Vector3 tmpScale = transform.localScale;
			tmpScale.x = Mathf.Abs(tmpScale.x);
			if(myParent.direction < 0)
				tmpScale.x = -tmpScale.x;
			//tmpScale.x = tmpScale.x * -myParent.direction;
			transform.localScale = tmpScale;
			
			transform.position = myParent.transform.position + myParent.getSpriteInatePos();
		}
	}
}
